<?php 
/* SVN FILE: $Id$ */
/* SearchController Test cases generated on: 2009-12-01 11:33:59 : 1259634839*/
App::import('Controller', 'Search');

class TestSearch extends SearchController {
	var $autoRender = false;
}

class SearchControllerTest extends CakeTestCase {
	var $Search = null;
	var $fixtures = array('app.product');
	function startTest() {
		$this->Search = new TestSearch();
		$this->Search->constructClasses();
	}

	function testSearchControllerInstance() {
		$this->assertTrue(is_a($this->Search, 'SearchController'));
	}

	function endTest() {
		unset($this->Search);
	}
	function testSearch(){
		echo("<p style='font-size:12pt;margin:0.5em'><b>サーチ</b></p>");
		$data = array(
  		  	"t" => "automation_book",
			"XDEBUG_PROFILE" =>"1"
		);
		$result = $this->testAction('/depot/search/search', array(
    		'data' => $data,
    		'fixturize' => false,
    		'method' => 'get',
    		'return' => 'vars')
		);
		#debug($result);
		
		$flash = $this->Search->Session->read('Message.flash');
		#debug($flash['message']);
		$this->assertEqual($flash['message'],'商品が見つかりました。');
		$this->assertTrue(!empty($result['products']));
		$products = $result['products'];
		$this->assertEqual(count($products),1);
		$this->assertEqual($products[0]['Product']['title'],'automation_book');
	}
	function testInvalidSearch(){
		echo("<p style='font-size:12pt;margin:0.5em'><b>不正サーチ</b></p>");
		$data = array(
  		  	"t" => "not_fount_book",
		);
		$result = $this->testAction('/depot/search/search', array(
    		'data' => $data,
    		'fixturize' => false,
    		'method' => 'get',
    		'return' => 'vars')
		);
		$flash = $this->Search->Session->read('Message.flash');
		$this->assertEqual($flash['message'],'商品が見つかりませんでした');
		$this->assertTrue(empty($result['products']));
	}
	function testInvalidSearchWithoutTitle(){
		echo("<p style='font-size:12pt;margin:0.5em'><b>不正サーチ（タイトル未指定)</b></p>");
		$result = $this->testAction('/depot/search/search', array(
    		'data' => null,
    		'fixturize' => false,
    		'method' => 'get',
    		'return' => 'vars')
		);
		#debug($result);
		
		$flash = $this->Search->Session->read('Message.flash');
		#debug($flash['message']);
		$this->assertEqual($flash['message'],'タイトルを入力してください');
		$this->assertTrue(empty($result['products']));
	}
}
?>